SHELL := /bin/bash
TOOLCHAIN_DIR := $(shell echo $${TOOLCHAIN_DIR:-/usr/local/k1tools/})
# Compilers
K1CC            ?= $(TOOLCHAIN_DIR)/bin/k1-gcc
CREATE_MULTIBIN ?= $(TOOLCHAIN_DIR)/bin/k1-create-multibinary

FILES := cluster.c Functions.c
IO_APP_NAME := demo_io
CLUSTER_APP_NAME := demo_cluster
MULTIBIN_NAME := demo.mpk

all:    mppa

mppa: clean
	${K1CC} -g -mos=nodeos ${FILES} -o ${CLUSTER_APP_NAME} -lmppaipc
	${K1CC} -g -mos=rtems test_io.c -o ${IO_APP_NAME} -lmppaipc
	${CREATE_MULTIBIN} --toolchain ${TOOLCHAIN_DIR} --clusters ${CLUSTER_APP_NAME} --boot=${IO_APP_NAME} -T ${MULTIBIN_NAME}

run-sim-traces:
	${TOOLCHAIN_DIR}/bin/k1-mppa -p -- ./${MULTIBIN_NAME}

.PHONY: clean
clean:
	rm -rf ${IO_APP_NAME} ${CLUSTER_APP_NAME} ${MULTIBIN_NAME}
